home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dirut / since_w.zip / SINCE.C < prev    next >
C/C++ Source or Header  |  1986-12-21  |  4KB  |  119 lines

  1. #include <stdio.h>
  2. #include <direct.h>
  3. #include <dos.h>
  4.  
  5. struct dosdta {
  6.    unsigned char  rsv[21];          /* reserved for DOS */
  7.    unsigned char  attrib;           /* attribute found */
  8.    unsigned int   ftime;            /* file's time */
  9.    unsigned int   fdate;            /* file's date */
  10.    long           fsize;            /* file size */
  11.    unsigned char  fspec[13];        /* file name.typ,0 */
  12.    };
  13.  
  14. unsigned int when = 0;
  15.  
  16. char *amonth[] = { "January", "February", "March", "April",
  17.                    "May", "June", "July", "August",
  18.                    "September", "October", "November", "December" };
  19.                    
  20. int   dmonth[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
  21.  
  22. void main(argc,argv)
  23. int  argc;
  24. char **argv;
  25. {
  26. union  REGS   regs;
  27. char holddir[65];
  28. unsigned int mm,dd,yy;
  29.  
  30.    if(argc != 4) {
  31.       fprintf(stderr,"Format is: since mm dd yy\n");
  32.       exit(100);
  33.       }
  34.    mm = atoi(argv[1]);
  35.    dd = atoi(argv[2]);
  36.    yy = atoi(argv[3]);
  37.    
  38.    if((mm < 1) || (mm > 12)) {
  39.       fprintf(stderr,"When did they change the number of months in a year?\n");
  40.       exit(4);
  41.       }
  42.       
  43.    if((( mm != 2) && (dmonth[mm-1] < dd)) || ((mm == 2) && (dd > 29))) {
  44.       fprintf(stderr,"When did they change the number of days in %s?\n",amonth[mm-1]);
  45.       exit(4);
  46.       }
  47.    
  48.    if(((yy < 1980) && (yy > 99)) || (yy < 80)) {
  49.       fprintf(stderr,"Bad year, must be >= 1980 or >79 and < 100\n");
  50.       exit(4);
  51.       }
  52.    
  53.    printf("Files since %02.2d-%02.2d-%d\t",mm,dd,yy);
  54.    if (yy >= 1980) yy -= 1980;
  55.    else yy -= 80;
  56.    
  57.    yy <<= 9;
  58.    mm <<= 5;
  59.    when = ( yy | mm | dd);
  60.    printf("x\'%4.4x\'\n",when);
  61.    
  62.    regs.x.ax = 0x4700;              /* get current directory */
  63.    regs.x.si = (short)&holddir[1];  /* where to put it */
  64.    regs.x.dx = 0;                   /* default drive */
  65.    intdos(®s,®s);             /* do it ... */
  66.    holddir[0] = '\\';               /* start off with backslash */
  67.    findmod("/");                    /* start at root directory */
  68.    chdir(holddir);                  /* change to original directory */
  69.  
  70. }
  71.  
  72. findmod(s)
  73. char *s;
  74. {
  75. static char allstr[] = "*.*";
  76. struct dosdta my_dta;
  77. char   holddir[65];
  78. union  REGS   regs;
  79. unsigned      i,k;
  80.  
  81.    chdir(s);                        /* change to specified directory */
  82.    regs.x.si = (short)&holddir[1];  /* area to hold current directory */
  83.    regs.x.ax = 0x4700;              /* get current directory function */
  84.    regs.x.dx = 0;                   /* default drive */
  85.    intdos(®s,®s);
  86.    holddir[0] = '\\';
  87.    if(holddir[1] == '\0') holddir[0] = '\0';
  88.  
  89.    regs.x.dx = (short)&my_dta;      /* new DTA */
  90.    regs.x.ax = 0x1a00;              /* set DTA function */
  91.    intdos(®s,®s);             /* do it ... */
  92.  
  93.    regs.x.ax = 0x4e00;              /* find first */
  94.    regs.x.dx = (short)&allstr[0];   /* *.* */
  95.    regs.x.cx = 0x10;                /* include subdirectories */
  96.    intdos(®s,®s);             /* do it */
  97.  
  98.    while(regs.x.cflag == 0) {
  99.       if((my_dta.attrib & 0x10) && (my_dta.fspec[0] != '.')) {
  100.          findmod(my_dta.fspec);
  101.          chdir("..");
  102.          regs.x.dx = (short)&my_dta;      /* new DTA */
  103.          regs.x.ax = 0x1a00;              /* set DTA function */
  104.          intdos(®s,®s);             /* do it ... */
  105.          }
  106.       else
  107.          if(my_dta.fdate >= when) {
  108.                k = (my_dta.fdate >> 9) + 1980;
  109.                printf("%02.2d-%02.2d-%d\t%s\\%s\n",
  110.                   ((my_dta.fdate & 0x1e0) >> 5),
  111.                   (my_dta.fdate & 0x1f),
  112.                   k,
  113.                   holddir,my_dta.fspec);
  114.             }
  115.       regs.x.ax = 0x4f00;           /* find first */
  116.       intdos(®s,®s);          /* do it */
  117.       }
  118. }
  119.